//auto gen by paipai.java.augogen ver 1.0
//author skyzhuang
#ifndef _GISCOREAO_GIS_H_
#define _GISCOREAO_GIS_H_

#include <stdint.h>
#include <string>
#include <iostream>
#include "app_platform/help_macros.h"
#include "app_platform/intf_service.h"
#include "intf_giscoreao.h"

#include "library/basic/singleton_t.h"
#include "library/basic/sync_lock.h"
#include "c2cent/library/log/CWTimeElf3.h"

#include <map>
#include "erp/gis/po/shiptypeareagischeckpo_gis.h"
#include "erp/gis/po/mergedcoordinatespo_gis.h"

HEADER_SELF_DEFINE_START
/**
*  请在这里增加自定义包含的头文件，否则无法合并代码
**/

#include "erp/gis/ddo/shiptypearealocusdo_gis.h"
#include "erp/gis/ddo/shiptypearealocusdolist_gis.h"
#include "erp/gis/po/coordinatesquerypo_gis.h"
#include "erp/gis/po/coordinatespo_gis.h"
#include "erp/gis/po/addrcoordinateresultpo_gis.h"

#include "giscoreao_dispatcher.h"
#include "geo_helper.h"

HEADER_SELF_DEFINE_END

namespace erp
{
namespace gis
{
namespace ao
{

#define GISCOREAO_SERVICE_VERSION "ERP_GIS_AO___GISCOREAO__SERVICE_VERSION__1.0 8174a85b1a393bb6da1af47c5458ae5f"
const std::string GISCOREAO_SERVICE_NOUSE = GISCOREAO_SERVICE_VERSION;

SERVICE class CGisCoreAo : public IGisCoreAo{
public:
		CGisCoreAo(enum DeployMethod method = DEPLOY_STANDALONE);
		~CGisCoreAo();
		 void Reset();
		static int Initialize(IUserDefineCntl* pCntl = NULL);

public:
	 /**
	 *
	 *   检测目标地址对应的配送方式是否被覆盖 
	 *
	 */
	EXPORT(0xc0221001) uint32_t CheckAreaCover(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const erp::gis::po::CShipTypeAreaGisCheckPo& oShipTypeAreaGisCheckPo,
		 const std::string& strInReserve,
		 std::map<uint32_t,uint32_t> & mapCheckResult,
		 std::string& strErrMsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   获取合并经纬度 
	 *
	 */
	EXPORT(0xc0221002) uint32_t GetMergeCoordinate(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const std::string& strDestAddrProvince,
		 const std::string& strDestAddrCity,
		 const std::string& strDestAddrDistrict,
		 const std::string& strDestAddrText,
		 const std::string& strInReserve,
		 erp::gis::po::CMergedCoordinatesPo& oMergedCoordinatesPo,
		 std::string& strErrMsg,
		 std::string& strOutReserve
		);

SECTION_SELF_DEFINE_START
/**
* 请在这里增加自定义的成员变量和函数，否则无法合并代码
**/
private:
		enum E_GET_COORDINATE_TYPE {
			E_GIS_COORDINATE_4CHECKAREA,
			E_GIS_COORDINATE_4PREMEARGE,
		};


		static int _InitTmem(IUserDefineCntl* pCntl);
		static int _InitAsynDispatcher(IUserDefineCntl* pCntl);

		uint32_t _CheckCommParameter(
		 		 const std::string& strMachineKey,
		 		 const std::string& strSource,
		 		 std::string& strErrMsg);

		uint32_t _CheckDestAddr(
				 const std::string& strDestAddrProvince,
				 const std::string& strDestAddrCity,
				 const std::string& strDestAddrDistrict,
				 const std::string& strDestAddrText,
				 std::string& strErrMsg);

		uint32_t _ValidateShipTypeAreaGisCheckPo(
				 const erp::gis::po::CShipTypeAreaGisCheckPo& oShipTypeAreaGisCheckPo,
				 std::string& strErrMsg);

		uint32_t _GetShipLocusFromTmem(
				 const erp::gis::po::CShipTypeAreaGisCheckPo& oShipTypeAreaGisCheckPo,
                 std::map<uint32_t, erp::gis::ddo::CShipTypeAreaLocusDoList>& mapShipType2GbCityIdShipLocus,
                 std::map<uint32_t, erp::gis::ddo::CShipTypeAreaLocusDoList>& mapShipType2GbProvinceIdShipLocus,
                 std::vector<erp::gis::ddo::CShipTypeAreaLocusDo>& vecFailed
		        );

		uint32_t _GetGisCoordinateByAddress(
 				 const CCntlInfo& rCntlInfo,
 				 const std::string& strMachineKey,
 				 const std::string& strSource,
 				 uint32_t dwSceneId,
 				 const std::string& strDestAddrProvince,
 				 const std::string& strDestAddrCity,
 				 const std::string& strDestAddrDistrict,
 				 const std::string& strDestAddrText,
 				 erp::gis::po::CCoordinatesPo& oClosestCoordinatePo,
 				 uint32_t& dwTrustLevel,
 				 std::string& strErrMsg,
 				 C2C_TIME_ELF_ITIL& oWTimeElf,
				 uint32_t dwCallDestination = E_GIS_COORDINATE_4CHECKAREA);

		std::string _GetShipAreaLocusTmemKey( 
		     		uint32_t dwShipType,
		     		uint32_t dwDestGbCityId);

		std::string _GenAddressTmemKey(const std::string& strAddress);

		void _GetGisCoordinateFromCmem(
			 const CCntlInfo& rCntlInfo,
			 const std::string& strMachineKey,
			 const std::string& strSource,
			 const std::string& strCmemKey,
			 erp::gis::po::CAddrCoordinateResultPo& oAddrCoordinateResultPo,
			 std::string& strErrMsg);

		void _SaveGisCoordianteToCmem(
			 const CCntlInfo& rCntlInfo,
			 const std::string& strMachineKey,
			 const std::string& strSource,
			 const std::string& strCmemKey,
			 erp::gis::po::CAddrCoordinateResultPo& oAddrCoordinateResultPo,
			 std::string& strErrMsg);

		void _ConvShipLocus2Coordinates(
			 const CCntlInfo& rCntlInfo,
			 const std::string& strMachineKey,
			 const std::string& strSource,
			 const erp::gis::ddo::CShipTypeAreaLocusDoList& oShipTypeAraLocusDoList,
			 std::vector<library::geo::CGeoCoordinate>& vecGeoCoordinate);

		void _ConvCoordinatesPo2GeoCoordinate(
			 const std::map<uint32_t, std::vector<erp::gis::po::CCoordinatesPo> >& mapResultApiTypeCoordinates,
			 std::map<uint32_t, library::geo::GeoGroup>& mapApiType2GeoCandinate);

		void _ReportItil4TrustLevel(uint32_t dwTrustLevel);
        void GetValueFromTmemKey(const std::string& strTmemKey, uint32_t& dwShipType, uint32_t& dwGbAreaId );
		


private:
		static uint32_t m_dwTmemBid;
		static uint32_t m_dwCoordinateResultTmemEnable;
        static uint32_t m_dwGisAreaLocusTmemEnable;
		
		
		static uint32_t m_dwTrustLevel;
		static uint32_t m_dwMaxRetryNum;
        static uint32_t m_dwShipAreaLocusCacheTimeOut;

		static std::string m_strLogModule;
		static CDispatcher m_oAsynDispatcher;
		static std::map<uint32_t, uint32_t> m_mapApiMapAndSwitch;
		
		static c2cent::library::wtimeelf::CItilGroup m_oCheckAreaCover;
		static c2cent::library::wtimeelf::CItilGroup m_oGetMergeCoordinate;

		erp::gis::ao::CLiber m_oLiber; // default.
		
SECTION_SELF_DEFINE_END

private:
	enum DeployMethod m_method;
};

}
}
}

#endif /* _GISCOREAO_GIS_H_ */
